// pages/retail-page/retail-page.js
const http = require('../../utils/http');
const apiConfig = require('../../utils/apiConfig');

Page({
  data: {
    goodsList: []
  },
  onLoad() {
    this.getGoodsList();
  },
  getGoodsList() {
    http.request({
      url: apiConfig.getGoodsList,
      method: 'GET',
      data: {
        page: 1,
        per_page: 10
      }
    }).then(res => {
      if (res.status === 200) {
        this.setData({
  goodsList: res.data.data.map(item => ({
    ...item,
    manufacturer: item.manufacturer?.manufacturer_name || '未知厂家',
    cost_price: item.cost_price,
    profit: (item.sales_price - item.cost_price).toFixed(2)
  }))
});
      }
    }).catch(err => {
      wx.showToast({ title: '商品加载失败', icon: 'none' });
      console.error('商品加载失败:', err);
    });
  }
});